home *** CD-ROM | disk | FTP | other *** search
- /*
- ** File mfdemo.c
- ** Source file for demonstration of
- ** MultiFile Select dialog
- **
- ** Copyright © Eric Schlegel 1987, 1988
- */
-
-
- #include <types.h>
- #include <quickdraw.h>
- #include <fonts.h>
- #include <events.h>
- #include <windows.h>
- #include <menus.h>
- #include <textedit.h>
- #include <dialogs.h>
- #include <packages.h>
- #include <memory.h>
- #include <segload.h>
- #include <files.h>
- #include "mfile.h"
-
- #define AppParmHandle (*((long *)(0xaec)))
-
- typedef struct parmhead {
- short msg;
- short count;
- } PARMHEAD;
-
- /* launch struct. See TN126 */
- typedef struct lstruct {
- StringPtr pfName;
- short param;
- short LC;
- long extBlockLen;
- short fFlags;
- long launchFlags;
- } LSTRUCT;
-
- pascal short dolaunch(lsp)
- LSTRUCT *lsp;
- extern;
-
- /* SFReply rec for SFGetFile for app */
- SFReply appreply;
- LSTRUCT ls;
-
- main()
- {
- Boolean getapp();
- void getdocs();
- void launchit();
-
- EventRecord ev;
- int ch;
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
-
- if (!getapp())
- ExitToShell();
-
- getdocs();
-
- launchit();
-
- /* we get here if under MultiFinder */
- /* wait for a cmd-Q */
- while (1)
- if (GetNextEvent(everyEvent, &ev))
- if ((ev.what == keyDown) || (ev.what == autoKey)) {
- ch = ev.message & charCodeMask;
- if (((ch == 'q') || (ch == 'Q')) &&
- (ev.modifiers & cmdKey))
- break;
- }
-
- ExitToShell();
- }
-
- /* use SFGetFile to get an application to */
- /* launch. returns true if user clicks OK */
- /* and false if user clicks Cancel */
- Boolean getapp()
- {
- Point where;
- SFTypeList types;
-
- SetPt(&where, 50, 50);
- types[0] = 'APPL';
- SFGetFile(&where, "", NULL, 1, types, NULL, &appreply);
- return(appreply.good);
- }
-
- /* get the documents with multifile() */
- void getdocs()
- {
- pascal Boolean docfilt();
- void mkdoclist();
-
- Point where;
- SFTypeList types;
-
- get_tl(&where);
- if (multifile(&where, "Select documents:", docfilt, -1, types))
- mkdoclist();
- }
-
- /* filefilter function for selecting documents */
- pascal Boolean docfilt(pb)
- ParmBlkPtr pb;
- {
- /* always show folders; also show noninvisible documents */
- if (pb->fileParam.ioFlAttrib & 0x10)
- return(true);
- else
- return((pb->fileParam.ioFlFndrInfo.fdFlags & fInvisible) ||
- (pb->fileParam.ioFlFndrInfo.fdType == 'APPL'));
- }
-
- /* set up the application parameters */
- void mkdoclist()
- {
- void newlist();
- void addfile();
-
- int nfiles;
- int i;
- FSTRUCT fstrct;
-
- newlist();
-
- nfiles = numfiles();
- for (i = 1; i <= nfiles; i++) {
- getfile(i, &fstrct);
- addfile(&fstrct);
- }
- }
-
- /* creates a new application parameters list */
- void newlist()
- {
- Handle parms;
- THz oldzone;
-
- /* if AppParmHandle already has a valid handle, */
- /* just resize it to the starting size. */
- if (parms = (Handle)AppParmHandle) {
- HUnlock(parms);
- SetHandleSize(parms, 4);
- return;
- }
-
- /* allocate memory in sysheap so it */
- /* stays around after we quit */
- oldzone = GetZone();
- SetZone(SystemZone());
-
- /* make sure we get the memory */
- if (parms = NewHandle(4)) {
- ((PARMHEAD *)(*parms))->msg = appOpen;
- ((PARMHEAD *)(*parms))->count = 0;
- }
-
- SetZone(oldzone);
-
- AppParmHandle = (long)parms;
- }
-
- /* adds file described by fstrct to app params list */
- void addfile(fstrct)
- FSTRUCT *fstrct;
- {
- Handle parms;
- long oldsize;
- int fsize;
- char *aptr;
-
- /* return if parms is null */
- if (!(parms = (Handle)AppParmHandle))
- return;
-
- /* get length of filename; if length of fname */
- /* plus length byte is odd, make it even */
- fsize = fstrct->fname.length;
- fsize++;
- if (fsize & 0x01)
- fsize++;
-
- /* grow parms to hold new file. */
- /* 8 bytes for vrefnum, type, */
- /* and version. */
- oldsize = GetHandleSize(parms);
- SetHandleSize(parms, oldsize + 8 + fsize);
-
- /* return if not enough mem */
- if (MemError())
- return;
-
- /* stuff in the file info */
- aptr = (char *)((long)*parms + oldsize);
- *((short *)aptr)++ = fstrct->vrefnum;
- *((long *)aptr)++ = fstrct->ftype;
- *((short *)aptr)++ = fstrct->fver;
- BlockMove(&fstrct->fname, aptr, fsize);
-
- /* increment file count */
- ((PARMHEAD *)(*parms))->count++;
- }
-
- /* launches application described by appreply */
- void launchit()
- {
- char fname[64];
- HParamBlockRec hpb;
-
- /* copy app name to fname. SFReply.fName is a Str63 */
- BlockMove(&appreply.fName, fname, 64);
-
- hpb.fileParam.ioCompletion = 0L;
- hpb.fileParam.ioNamePtr = fname;
- hpb.fileParam.ioVRefNum = appreply.vRefNum;
- hpb.fileParam.ioFDirIndex = 0;
- hpb.fileParam.ioDirID = 0L;
- PBHGetFInfo(&hpb, false);
-
- /* set current volume to app's directory */
- SetVol(NULL, appreply.vRefNum);
-
- /* set up launch struct. param=0 indicates */
- /* no alternate screen or sound buffers */
- ls.pfName = fname;
- ls.param = 0;
- ls.LC = 'LC';
- ls.extBlockLen = 6;
- ls.fFlags = hpb.fileParam.ioFlFndrInfo.fdFlags;
- ls.launchFlags = 0x40000000;
-
- /* ignore the error code after launch */
- (void)dolaunch(&ls);
- }